package com.baidu.flutter_bmflocation;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import io.flutter.plugin.common.MethodChannel;
import android.util.Log;
public class MethodChannelManager {
    /* 声明实例对象 */
    private static volatile MethodChannelManager sInstance;

    private static class PendingCall {
        final String methodID;
        final Object value;
        final int errorCode;

        PendingCall(String methodID, Object value, int errorCode) {
            this.methodID = methodID;
            this.value = value;
            this.errorCode = errorCode;
        }
    }

    private final List<PendingCall> mPendingCalls = new ArrayList<>();

    // 声明methodChannel
    private MethodChannel mLocationChannel;

    private MethodChannel mGeofenceChannel;

    /* 返回实例对象 */
    public static MethodChannelManager getInstance() {
        if (null == sInstance) {
            synchronized (MethodChannelManager.class) {
                if (null == sInstance) {
                    Log.d("cxbswc getInstance", "sInstance is null");
                    sInstance = new MethodChannelManager();
                }
            }
        }
        return sInstance;
    }

    // 设置methodChannel
    public synchronized void putLocationChannel(MethodChannel methodChannel) {
        mLocationChannel = methodChannel;
    }

    public synchronized void putGeofenceChannel(MethodChannel methodChannel) {
        mGeofenceChannel = methodChannel;
    }

    // 获取channel
    public synchronized MethodChannel getLocationChannel() {
        return mLocationChannel;
    }

    public synchronized MethodChannel getGeofenceChannel() {
        return mGeofenceChannel;
    }

} 